package com.itheima.job;


import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.util.concurrent.Future;

/*异步任务调度类*/
@Component
public class MyTask2 {



    // 任务一
    @Async
    public Future<String> task1(){
        long start = System.currentTimeMillis();
        try {
            Thread.sleep(4000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        long end = System.currentTimeMillis();
        System.out.println("任务1执行完成,耗时："+(end-start));
        return new AsyncResult<>("ok");

    }


    // 任务二
    @Async
    public Future<String> task2(){
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("任务2执行完成");
        return new AsyncResult<>("ok");

    }

    // 任务三
    @Async
    public Future<String> task3(){
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println("任务3执行完成");
        return new AsyncResult<>("ok");

    }



}
